<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>

<s:property value="cityname"/>
<span id="${dvid}_p" style="display:none"></span>
<span id="${dvid}_c" style="display:none"></span>
<span id="${dvid}_a" style="display:none"></span>
<span id="${dvid}_t" style="display:none"></span>
<s:if test="jaddress">
<span id="${dvid}_t"><input id="t_${dvid}_t" type="text"/></span>
</s:if>

<script type="text/javascript">
<!--
function class_lcity(dvid){this.l_dvid=dvid;}
var lcity= new class_lcity("${dvid}");
	class_lcity.prototype.reload=function(cid){
		var dvid=this.l_dvid;
		var fun=function(data){
			if(1==data.s){
				initsp();
				if(null!=data.pl){
					createSel(dvid+"_p",0);
					loadsel("s_"+dvid+"_p",-1,"请选择",true,data.pv);
					for (var index in data.pl) {
						loadsel("s_"+dvid+"_p",index,data.pl[index],false,data.pv);
					}
					$("#"+dvid+"_p").show();
				}
				if(null!=data.cl){
					createSel(dvid+"_c",10);
					loadsel("s_"+dvid+"_c",-1,"请选择",true,data.cv);
					for (var index in data.cl) {
						loadsel("s_"+dvid+"_c",index,data.cl[index],false,data.cv);
					}
					$("#"+dvid+"_c").show();
				}
				if(null!=data.al){
					createSel(dvid+"_a",20);
					loadsel("s_"+dvid+"_a",-1,"请选择",true,data.av);
					for (var index in data.al) {
						loadsel("s_"+dvid+"_a",index,data.al[index],false,data.av);
					}
					$("#"+dvid+"_a").show();
				}
				if(null!=data.tl){
					createSel(dvid+"_t",30);
					loadsel("s_"+dvid+"_t",-1,"请选择",true,data.tv);
					for (var index in data.tl) {
						loadsel("s_"+dvid+"_t",index,data.tl[index],false,data.tv);
					}
					$("#"+dvid+"_t").show();
				}
			}
		};
		exeAjax(ajaxUrl("${aier_url}${aier_urijs}cityutil!gsub${aier_suffix}"), fun, {"cityid" :cid});
		
		function loadsel(id,v,c,init,seld){
      		if(init){$("#"+id).html("");}
      		var html="<option value='"+v+"'";
      		if(v==seld){html+=" selected='selected'";}
      		$("#"+id).append(html+">"+c+"</option>"); 
      	}
      	
		function initsp(){
		    $("#"+dvid+"_p").hide();$("#"+dvid+"_c").hide();$("#"+dvid+"_a").hide();$("#"+dvid+"_t").hide();
      	}
      	
      	function createSel(sid,ct){
      	    var higher = null;
            switch(ct){
            case 0:break;
            case 10:higher = "s_"+id+"_p";break;
            case 20:higher = "s_"+id+"_c";break;
            case 30:higher = "s_"+id+"_a";break;
            }
      		$("#"+sid).html("<select style='border-color: #45930b;' id='s_"+sid+"' onchange='loadcity(this,"+ct+","+higher+")'></select>");
      	}
	};
function load(cid){
lcity.reload(cid);
}

load(<s:property value="cityid"/>);

function class_acity(dvid){this.a_dvid=dvid;}
	var acity= new class_acity("${dvid}");
	
	class_acity.prototype.load=function(me,cid,sct,higher){
	     
	    if (sct !=0 && cid == -1) {
	        this.cid = higher.value;
	    } else {
	        this.cid=cid;
	    }
		var dvid=this.a_dvid;
		var thisme=this;
		this.sct=sct;
		if(!isnull(me)){
			this.cname=me.options[me.selectedIndex].text;
		}
		
		var fun=function(data){
			var ct=data.ct;
			thisme.subname=data.subname;
			
			if(1==data.s){
			initsp();
			$("#"+dvid+"_p").show();
			
			var cl=data.cl;
				var lselid="";
				
				switch(ct){
				case 0:
					lselid="s_"+dvid+"_p";
					break;
				case 10:
					if(data.count<=0&&ct>0) {
					   loadsel("s_"+dvid+"_c","-1","无数据",true);
					   loadsel("s_"+dvid+"_a","-1","无数据",true);
					   loadsel("s_"+dvid+"_t","-1","无数据",true);
					   return;
					}
					$("#"+dvid+"_c").show();
					lselid="s_"+dvid+"_c";
					break;
				case 20:
					$("#"+dvid+"_c").show();
					if(data.count<=0&&ct>0) {
					   loadsel("s_"+dvid+"_a","-1","无数据",true);
					   loadsel("s_"+dvid+"_t","-1","无数据",true);
					   return;
					}
					$("#"+dvid+"_a").show();
					lselid="s_"+dvid+"_a";
					break;
				case 30:
					$("#"+dvid+"_c").show();
					$("#"+dvid+"_a").show();
					if(data.count<=0&&ct>0){
					   loadsel("s_"+dvid+"_t","-1","无数据",true);
					   return;
					}
					$("#"+dvid+"_t").show();
					lselid="s_"+dvid+"_t";
					break;
				}
				createSel(dvid,ct);				
				loadsel(lselid,"-1","请选择",true);
				for (var index in cl) {
					loadsel(lselid,index,cl[index],false);
				}
			}else{
				switch(ct){
				case 0:
					initsp();
					$("#"+dvid+"_p").show();
					loadsel("s_"+dvid+"_p","-1","无数据",true);
					break;
				case 10:
					initsp();
					$("#"+dvid+"_c").show();
					loadsel("s_"+dvid+"_c","-1","无数据",true);
					break;
				case 20:
					initsp();
					$("#"+dvid+"_a").show();
					loadsel("s_"+dvid+"_a","-1","无数据",true);
					break;
				case 30:
					initsp();
					$("#"+dvid+"_t").show();
					loadsel("s_"+dvid+"_t","-1","无数据",true);
					break;
				}
			}
		};
		if(cid==-1){
			var tcid="";
			switch(sct){
			case 0:
			    $("#"+dvid+"_c").hide();
			    $("#"+dvid+"_a").hide();
			    $("#"+dvid+"_t").hide();
			case 10:
				//$("#"+dvid+"_c").hide();
				$("#"+dvid+"_a").hide();
				$("#"+dvid+"_t").hide();
				break;
			case 20:
				//$("#"+dvid+"_a").hide();
				$("#"+dvid+"_t").hide();
				break;
			case 30:
				//$("#"+dvid+"_t").hide();
				break;
			}
			return;
		}
		
		if(sct!=0&&sct!=10&&sct!=20){
			return;
		}
		
		exeAjax(ajaxUrl("${aier_url}${aier_urijs}cityutil${aier_suffix}"), fun, {"cityid" :cid});
		
		function initsp(){
		    $("#"+dvid+"_p").hide();$("#"+dvid+"_c").hide();$("#"+dvid+"_a").hide();$("#"+dvid+"_t").hide();
      	}
      	
      	function loadsel(id,v,c,init){
      		if(init){$("#"+id).html("");}
      		$("#"+id).append('<option value="'+v+'">'+c+'</option>'); 
      	}
      	
      	function createSel(id,ct){
      		var sid="";
      		var selid="";
      		var higher = null;
      		switch(ct){
      		case 0:sid=id+"_p";selid="s_"+id+"_p";break;
      		case 10:sid=id+"_c";selid="s_"+id+"_c";higher = "s_"+id+"_p";break;
      		case 20:sid=id+"_a";selid="s_"+id+"_a";higher = "s_"+id+"_c";break;
      		case 30:sid=id+"_t";selid="s_"+id+"_t";higher = "s_"+id+"_a";break;
      		}
      		$("#"+sid).html("<select style='border-color: #45930b;' id='"+selid+"' onchange='loadcity(this,"+ct+","+higher+")'></select>");
      	}
	};
	function loadcity(me,ct,higher){
		acity.load(me,me.value,ct,higher);
	}
//-->
</script>
